<?php
 /**
 * filename: article_edit.php
 * goal: get the article and edit it
 */
require_once 'connect.php';
session_start();
if(isset ($_SESSION['permission'])&& $_SESSION['permission'] == 1) {
    //something code here
} else {
    //header('Location: login.php');
}
?>

<html>
    <head>
        <title>Administrator</title>
        <style type="text/css">
            body{
                margin: 0px auto;
                width: 960px;
                border: 2px solid #cccccc;
                -moz-boder-radius: 15px;
                line-height: 1.6;
            }                
        </style>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
        <link rel="stylesheet" href="css/adminStyle.css"/>
        <script language="Javascript" src="../scripts/innovaeditor.js"></script>
        <script language="javascript" type="text/javascript" src="../js/datetimepicker.js"></script>
    </head>
    
    <body>
        <div id="header">
            <div class="logo"></div>
            <div id="logout">
                <ul>
                    <li><a href="../index.php">Home</a></li>
                    <li><a href="#">Logout</a></li>
                </ul>               
            </div>
        </div>

            <?php
                    $uNews = $_REQUEST['uNews'];
                    require('get_data.php');
                    $data = new PushData();
                    $article = $data->loadArticle($uNews);                 
            ?>          
            <form name="f" action="article_edit_act.php?uNews=<?php echo $article->uNews; ?>" method="post">
                <fieldset align="center">
                    <legend><b><i>Edit Article Form</i></b></legend>
                <table align="center" width="95%" border="1" cellpadding="2" cellspacing="0">
                    <tr>
                        <th align="left" width="130px">uNews</th>
                        <td><?php echo $article->uNews; ?></td>
                    </tr>
                    
                    <tr>
                        <th align="left">Title</th>
                        <td><input type="text" name="title" width=650 value="<?php echo $article->title; ?>"</td>
                    </tr>
                    
                    <tr>
                        <th align="left">Description</th>
                        <td><textarea rows="5" cols="50" name="description"><?php echo $article->description; ?></textarea></td>
                    </tr>
                    
                    <tr>
                        <th align="left">Image</th>
                        <td>
                            <input type=text style="width:200px;" name="image" id="image" value="<?php echo $article->image;?>">
                            <input type="button" onClick="window.open('browse_add.php','','scrollbars=1,width=500,height=500');" value="Browse">	
                            <input type="button" onClick="window.open('upload_add.php','','width=300,height=200');" value="Upload">                        </td>
                    </tr>
                    
                    <tr>
                        <th align="left">Content</th>
                        <td width="285"><textarea name="content" cols="28" rows="5" id="content"><?php echo $article->content;?></textarea>
                            <script>
                                var oEdit1 = new InnovaEditor("oEdit1");
                                oEdit1.width="760px";
                                oEdit1.height="250px";
                                oEdit1.REPLACE("content");
                            </script>
                        </td>
                    </tr>
                    
                    <tr>
                        <th align="left">author</th>
                        <td><input type="text" name="author" width=650 value="<?php echo $article->author; ?>"/></td>
                    </tr>
                    
                    <tr>
                        <th align="left">Date</th>
                        <td>
                            <input name="date" id="date" type="text" size="25" value="<?php echo $article->date;?>"><a href="javascript:NewCal('date','ddmmyyyy')"><img src="../images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
			</td>
                    </tr>
                    
                    <tr>
                        <th align="left">Statement</th>
                        <td>
                            <select name="statement" id="statement">
                                    <option value="1">Enabled</option>;
                                    <option value="0">Disabled</option>;
                        </td>
                    </tr>
                    
                    <tr>
                        <td align="right"><input type="submit" value="Publish" onclick="checkValue();" align="right"/></td>
			<td><input type="reset" value="Reset" align="left"></td>
                    </tr>
                    <script languge="javascript">
                    function checkValue()
                    {
                        if(f.title.valueOf() == '') {
                            alert('You need to fill in your article tile');
                            f.title.focus();
                            return false;
                        }
                        if(f.Content.valueOf() == '') {
                            alert('Article does not have content');
                            f.title.focus();
                            return false;
                        }
                        confirm('You really want to publish ?');
                        return true;
                    }
                    </script>
                
                </table>   
                </fieldset>
            </form>
			
			
            <div class="footer-admin">
                <h3 align="center"><a href="index.php">Contact us</a<></h3>
            </div>
            
        </body>
</html>
